<%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@ page isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
  String path = request.getContextPath();
  String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
  String _id=request.getParameter("_");
%>

<div class="row">
    <div class="col-lg-12">
        <div class="panel">
            <div class="panel-heading header">
                <h3 class="panel-title" id="title">公告通知登记表</h3>
            </div>

            <div style="margin: 10px">

                <!-- Nav tabs -->
                <ul class="nav nav-tabs">
                    <li class="active"><a href="#s1" data-toggle="tab">公告通知</a></li>
                    <c:if test="${notice.processState=='Finished'}"><li class="disabled"><a href="#s2" id="other2" data-toggle="tab">浏览情况</a></li></c:if>
                </ul>

                <!-- Tabs Content -->
                <div class="tab-content">

                    <div class="tab-pane pad-btm fade in active" id="s1">
                        <!-- BASIC FORM ELEMENTS -->
                        <!--===================================================-->
                        <form id="form_notice_input" class="panel-body form-horizontal form-padding">

                            <input type="hidden" name="keyId" id="keyId" value="${notice.id}" />
                            <input type="hidden" name="curDutyId" id="curDutyId" value=""/>

                            <div class="form-group">
                                <label class="col-md-2 control-label">公告主题<i class="fa fa-asterisk txt-color-red"></i></label>
                                <div class="col-md-6">
                                    <input type="text" id="subject" name="subject" class="form-control" disabled value="${notice.subject}">
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-md-2 control-label">是否置顶<i class="fa fa-asterisk txt-color-red"></i>
                                </label>
                                <div class="col-md-6">
                                    <input type="text" id="isTop" name="isTop" class="form-control" disabled value=${notice.isTop==1?'是':'否'}>
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-md-2 control-label">公告类型<i class="fa fa-asterisk txt-color-red"></i>
                                </label>
                                <div class="col-md-6">
                                    <input type="text" id="dictItem" name="dictItem" class="form-control" disabled value="${notice.name}">
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-md-2 control-label">
                                    发布部门
                                    <i class="fa fa-asterisk txt-color-red"></i>
                                </label>
                                <div class="col-md-6">
                                    <input type="text" id="deptName" name="deptName" class="form-control" disabled value="${notice.issueDepartment.name}">
                                </div>
                            </div>

                            <c:if test="${notice.numStatus<1}">
                            <div class="form-group">
                                <label class="col-md-2 control-label">通知对象<i class="fa fa-asterisk txt-color-red"></i>
                                </label>
                                <div class="col-md-6">
                                    <input type="text" id="noticeType" name="noticeType" class="form-control" disabled value="${notice.noticeType}">
                                </div>
                            </div>

                            <div class="form-group" id="divNoticeDepts">
                                <label class="col-md-2 control-label">
                                    通知部门
                                    <i class="fa fa-asterisk txt-color-red"></i>
                                </label>
                                <div class="col-md-6">
                                    <input type="text" id="deptNames" name="deptNames" class="form-control" disabled
                                           value="<c:forEach var="item" items="${notice.noticeDepartments}" varStatus="status">${item.name}<c:if test="${!status.last}">,</c:if></c:forEach>">
                                </div>
                            </div>

                            <div class="form-group" id="divNoticeUsers">
                                <label class="col-md-2 control-label">
                                    通知个人
                                    <i class="fa fa-asterisk txt-color-red"></i>
                                </label>
                                <div class="col-md-6">
                                    <input type="text" id="userNames" name="userNames" class="form-control" disabled
                                           value="<c:forEach var="item" items="${notice.noticeUsers}" varStatus="status">${item.name}<c:if test="${!status.last}">,</c:if></c:forEach>">
                                </div>
                            </div>
                            </c:if>

                            <div class="form-group">
                                <label class="col-md-2 control-label">内容<i class="fa fa-asterisk txt-color-red"></i></label>
                                <div class="col-md-6">
                                    <input type="text" id="content" name="content" class="form-control" disabled value="${notice.content}">
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-md-2 control-label">附件上传</label>
                                <div class="col-md-6">
                                    <input name="uploadify" id="filename" style="display: none"  placeholder="" type="file" >
                                    <input name="fileId" id="fileId" style="display: none" value="${fileId}">
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-md-2 control-label">发布人</label>
                                <div class="col-md-2">
                                    <p class="form-control-static">${notice.creater.name}</p>
                                </div>
                                <label class="col-md-2 control-label">发布日期</label>
                                <div class="col-md-2">
                                    <p class="form-control-static"><fmt:formatDate pattern="yyyy-MM-dd" value="${notice.dateApply}" /></p>
                                </div>
                            </div>

                            <c:if test='${notice.processState=="Running" || notice.processState=="Backed"}'>
                                <div class="form-group" id="comment">
                                    <label class="col-md-2 control-label">审批意见</label>
                                    <div class="col-md-6">
                                        <textarea name="editor" id="editor" style="height:200px;"></textarea>
                                    </div>
                                </div>
                            </c:if>

                            <div class="flow">
                                <div class="panel-footer">
                                    <a class="btn btn-default" id="apply-re-common" href="javascript:void(0)">
                                        <i class="fa fa-lg fa-mail-reply"></i> 返回
                                    </a>
                                    <a class="btn btn-default"  key="ajax_edit" href="javascript:void(0);" ${isEdit}>
                                        <i class="fa fa-lg fa-edit"></i> 编辑
                                    </a>

                                </div>
                                <div class="f_title"><i class="right" id="flow"></i>流程信息</div>
                                <div class="f_content" style="display:none">
                                    <div id="showFlow"></div>
                                </div>
                                <div class="f_title"><i class="right" id="next"></i>下一步骤提示</div>
                                <div class="f_content" style="display:none">
                                    <div id="showNext"></div>
                                </div>
                            </div>


                        </form>
                        <!--===================================================-->
                        <!-- END BASIC FORM ELEMENTS -->

                    </div>

                    <div class="tab-pane fade" id="s2">
                        <div class="table-responsive" style="min-height: 530px;margin: 10px">
                            <table id="notice_read_table"></table>
                            <div id="notice_read_page"></div>
                        </div>
                    </div>

                </div>
            </div>

        </div>
    </div>
</div>

<script>
    var state = "${notice.processState}";
    var index = "${index}";
    var todo = "${todo}";
    var remind = "${remind}";
    var record = "${record}";
    var draft =  "${draft}";

    if(state == "Finished"){
        $('#other2').parent('li').removeClass('disabled');
    }

    // 附件显示
    readLoad({
        objId:"filename",
        entityName:"fileIds",
        sourceId:"fileId"
    });

    //编辑
    $("a[key='ajax_edit']").unbind("click").bind("click",function(){
        loadURL("<%=path%>/com/notice/input?keyId="+$("#keyId").val()+"&draft="+draft+"&todo="+todo+"&remind="+remind+"&record="+record+"&index="+index,$('#page-content'));
    });

    //返回视图
    $("#apply-re-common").click(function(){

        if(index==1){
            loadURL("menu/dashboard",$('#page-content'));
        }else if(todo==1){
            loadURL("menu/toDo",$('#page-content'));
        }else if(remind==1){
            loadURL("menu/remind",$('#page-content'));
        }else if(record==1){
            loadURL("menu/taskRecord?type=1",$('#page-content'));
        }else if(record==2){
            loadURL("menu/taskRecord?type=2",$('#page-content'));
        }else if(draft==1){
            loadURL("menu/draft",$('#page-content'));
        }else{
            returnToHashUrl()
        }

    });

    // 加载完成后执行
    $(function(){
        var tmp = $("#noticeType").val();
        if(tmp == "1"){
            $("#divNoticeDepts").show();
            $("#divNoticeUsers").hide();
            $("#noticeType").val("部门");
        } else if(tmp=="2"){
            $("#divNoticeDepts").hide();
            $("#divNoticeUsers").show();
            $("#noticeType").val("个人");
        } else {
            $("#divNoticeDepts").hide();
            $("#divNoticeUsers").hide();
            $("#noticeType").val("全体员工");
        }



        loadURL("<%=path%>/com/running/workflow?bussinessId="+$("input#keyId").val()+"&type=flow",$('#showFlow'));
        loadURL("<%=path%>/com/running/workflow?bussinessId="+$("input#keyId").val()+"&type=next",$('#showNext'));
        __ajax_post("<%=path%>/com/running/operateType",{keyId: $("input#keyId").val()},function(pdata){
            var showDuty = false;
            var area = $("form .panel-footer");
            var edit = null;
            $(pdata.datarows).each(function(i,v){
                var str = '<a id="left_foot_btn_'+ v.action+'" class="btn btn-warning" href="javascript:void(0);"><i class="fa fa-upload">'+ v.name+'</i></a>&nbsp;';
                $(area).append(str);
                if(v.action == "approve" || v.action=="sendback"  || v.action=="deny"){
                    showDuty = true;
                }
            });
            if(showDuty == true){
                var pdata = {
                    keyId: $("input#keyId").val(),
                    entityName: "com.fz.us.oa.core.entity.com.Notice"
                };
                multiDuty(pdata);
            }else{
                $('#comment').hide();
            }
            if($(':visible#editor').length == 1){
                edit  = new UE.ui.Editor();
                edit.render('editor');
                /*
                 edit.ready(function() {
                 edit.setContent("");
                 });*/
            }
            //通过
            $("#left_foot_btn_approve").off("click").on("click",function(){
                var comment = "";
                if(edit != null){
                    comment = encodeURIComponent(edit.getContent());
                }
                if($.trim(comment) == ""){
                    alert("请填写审批意见");
                    return false;
                }
                __form_save("form_notice_input","<%=path%>/com/notice/approve?comment="+comment,function(){
                    $("#apply-re-common").trigger("click");
                })
            });
            //退回
            $("#left_foot_btn_sendback").off("click").on("click",function(){
                var comment = "";
                if(edit != null){
                    comment = encodeURIComponent(edit.getContent());
                }
                if($.trim(comment) == ""){
                    alert("请填写审批意见");
                    return false;
                }
                var vActionUrl="<%=path%>/com/notice/back?comment="+comment+"&curDutyId="+$('#curDutyId').val();
                var data={keyId:$("input#keyId").val()};
                __ajax_post(vActionUrl,data,function(pdata){
                    __toastr(pdata);
                    $("#apply-re-common").trigger("click");
                });
            });
            //否决
            $("#left_foot_btn_deny").off("click").on("click",function(){
                var comment = "";
                if(edit != null){
                    comment = encodeURIComponent(edit.getContent());
                }
                if($.trim(comment) == ""){
                    alert("请填写审批意见");
                    return false;
                }
                var vActionUrl="<%=path%>/com/notice/deny?comment="+comment+"&curDutyId="+$('#curDutyId').val();
                var data={keyId:$("input#keyId").val()};
                __ajax_post(vActionUrl,data,function(pdata){
                    __toastr(pdata);
                    $("#apply-re-common").trigger("click");
                });
            });
        });

        //流程信息展开
        $('#flow,#next').click(function(){
            if($(this).hasClass("right")){
                $(this).removeClass("right").addClass("down");
                $(this).parent(".f_title").next("div.f_content").show();
            }else{
                $(this).removeClass("down").addClass("right");
                $(this).parent(".f_title").next("div.f_content").hide();
            }
        });
        
        

        init_grid_noticeread();
        jQuery("#notice_read_table").jqGrid('setGridWidth',  $("#s1").width()-55);
    });

    function init_grid_noticeread() {

        __init_jqgrid('notice_read_table', 'notice_read_page',
            '<%=path%>/com/notice/readList?noticeId='+$("#keyId").val(),
            ['查看人', '查看日期', 'id'],
            [
                {name: 'reader', index: 'reader', width: 100, sortable: false, search: false},
                {name: 'createTime', index: 'createTime', width: 160, sortable: false, search: false},
                {name: 'id', index: 'id', width: 100, key: true, hidden: true, hidedlg: true}
            ],
            true,true
        );

    }
</script>




